
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <c:if test="${requestScope.vipBookList==null }">
    	 <jsp:forward page="AdminSelectVipBook" />
    </c:if>
    
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>user</title>
</head>
<script src="assets/jquery/jquery-3.7.1.js" type="text/javascript" charset="utf-8" ></script>
<style>
  table {
    width: 100%;
    border-collapse: collapse;
    margin: 25px 0;
    font-size: 0.8em;
    min-width: 400px;
    border-radius: 5px 5px 0 0;
    overflow: hidden;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
  }
  th, td {
    padding: 12px 15px;
    text-align: center;

    border-bottom: 1px solid #dddddd;
  }
  th {
    font-size: 20px;
    background-color: #009879;
    color: #ffffff;
    text-align: center;
  }
  tr {
    background-color: #f3f3f3;
  }
  tr:nth-of-type(even) {
    background-color: #dddddd;
  }
  button {
  background-color: #4CAF50; /* 按钮颜色 */
  border: none;
  color: white; /* 文字颜色 */
  padding: 7px 15px; /* 内边距 */
  text-align: center; /* 文字居中 */
  text-decoration: none;
  display: inline-block;
  font-size: 16px; /* 字体大小 */
  margin: 4px 2px;
  cursor: pointer;
  border-radius: 16px; /* 圆角边框 */
  transition: background-color 0.3s; /* 过渡效果 */
}
 
button:hover {
  background-color: green; /* 鼠标悬浮颜色 */
}
a{
	text-decoration: none;
	color :white;
}
img{
	width:100px;
	height:133px;
}
textarea {
    -webkit-appearance: none; /* 移除默认样式 */
    overflow: hidden; /* 隐藏滚动条 */
    
}
input{
		height:40px;
		font-size:20px;
}
th{
	background-color: black;
}
</style>
<body>
  <table id="myTable">
  <tr>
   <th>轮播序号</th>
    <th>小说id</th>
    <th>小说名</th>
    <th>修改</th>
  </tr>
		<c:forEach items="${vipBookList}" var="lb">
        <tr>
            <td>${lb.vipBookId}</td>
            <td id="novelId-${lb.vipBookId}">${lb.novelId}</td>
            <td>${lb.novelName}</td>
            <td><button class="updateBtn" data-id="${lb.vipBookId}">修改</button></td>
        </tr>
    </c:forEach>
</table>

</body>
<script>
document.querySelectorAll('.updateBtn').forEach(button => {
    button.addEventListener('click', function() {
        const vipBookId = this.getAttribute('data-id');
        const novelIdTd = document.getElementById('novelId-' + vipBookId);
        const novelIdValue = novelIdTd.textContent;

        // 创建一个文本框并设置其值
        const textBox = document.createElement('input');
        textBox.type = 'text';
        textBox.value = novelIdValue;
        textBox.id = 'novelIdInput-' + vipBookId;

        // 创建一个确定按钮
        const confirmButton = document.createElement('button');
        confirmButton.textContent = '确定';
        confirmButton.onclick = function() {
            // 这里调用AJAX请求，将新的小说ID发送到服务器
        	$.ajax({
        		"type":"post",
        		"url":"updateVIP",
        		"data":{
        			"novelId":  textBox.value ,
        			"vipBookId":vipBookId
        			},
        		"dateType":"JSON",
        		"success":function(num){
        			if(num==1){
        				
        				alert("修改成功");
        				window.location = "lb.jsp";
        			}
        			//console.log(jsonObj.listUser[0].userId);
        		},
        		"error":function(){
        			console.log("失败");
        		}
        });
           
            
            // 这里可以添加其他逻辑，如还原按钮和文本框
        };

        // 替换td内容为文本框和确定按钮
        novelIdTd.innerHTML = '';
        novelIdTd.appendChild(textBox);
        // 替换原按钮为文本框和确定按钮
        this.style.display = 'none';
        this.parentNode.appendChild(confirmButton);

       
    });
});
</script>
</html>